﻿


namespace System.Threading
{
#if !NET40
    public struct CancellationToken
    {
        public static CancellationToken None
        {
            get { return default(CancellationToken); }
        }

        public bool IsCancellationRequested
        {
            get { return CancellationTokenSource != null && CancellationTokenSource.IsCancellationRequested; }
        }

        public void ThrowIfCancellationRequested()
        {
            if (IsCancellationRequested)
                throw new OperationCanceledException();
        }

        private CancellationTokenSource CancellationTokenSource { get; set; }


        internal CancellationToken(CancellationTokenSource cts)
            : this()
        {
            CancellationTokenSource = cts;
        }
    }

#endif

}